package com.sany.taskmanager.ui.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.sany.taskmanager.R;

public class EmptyView extends LinearLayout {

    public EmptyView(Context context) {
        this(context, null);
    }

    public EmptyView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public EmptyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view = LayoutInflater.from(context).inflate(R.layout.layout_empty, null);
        // 设置图片的宽高
        ImageView ivEmpty = view.findViewById(R.id.iv_empty);
        TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.EmptyView);
        int picHeight = mTypedArray.getInt(R.styleable.EmptyView_pic_height, 100);
        int picWidth = mTypedArray.getInt(R.styleable.EmptyView_pic_width, 100);
        ViewGroup.LayoutParams layoutParams = ivEmpty.getLayoutParams();
        layoutParams.height = picHeight;
        layoutParams.width = picWidth;
        ivEmpty.setLayoutParams(layoutParams);
        // 设置文字内容
        TextView tvEmpty = view.findViewById(R.id.tv_empty);
        String emptyText = mTypedArray.getString(R.styleable.EmptyView_empty_text);
        float textSize = mTypedArray.getDimension(R.styleable.EmptyView_empty_text_size, getResources().getDimension(R.dimen.px_18));
        tvEmpty.setText(emptyText);
        tvEmpty.setTextSize(textSize);
        mTypedArray.recycle();
        addView(view);
    }
}
